package com.gosophia.reportData.action;

import java.io.File;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.security.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

import com.gosophia.commons.web.action.BaseSupportAction;
import com.gosophia.reportData.dto.ReportJobDTO;
import com.gosophia.reportData.ws.ReportJobWebService;
import com.gosophia.springsecurity.UserDetailsImpl;
import com.opensymphony.xwork2.ActionContext;

/**
 * 附件上报
 * 
 * @author zhao_yanfang
 * 
 */

@Component
@Scope("prototype")
public class AttachmentReportAction extends BaseSupportAction {

	private ReportJobDTO reportingDto;
	private File[] files;
	private String[] filesFileName;
	private String[] filesNode;
	private long jobId;
	private long launchId;
	private String reportDescription;
	
	private String fromFlag;
	@Autowired
	private ReportJobWebService reportDataWebService;

	public String _execute() throws Exception {
		UserDetailsImpl userDetails = (UserDetailsImpl) SecurityContextHolder
				.getContext().getAuthentication().getPrincipal();
		Long userInfoId = userDetails.getUserAccountDTO().getUserInfoDTO()
				.getUserInfoId();
		reportingDto=new ReportJobDTO();
//		List<DocumentDTO> attachments = new ArrayList<DocumentDTO>();
//		for (int i = 0; i < files.length; i++) {
//			DocumentDTO attachment = new DocumentDTO();
//			String filePath = FileUpload.fileUpload(files[i], filesFileName[i]);
//			attachment.setDownLoadName(filesFileName[i]);
//			attachment.setDescription(filesNode[i]);
//			attachment.setPath(filePath);
//			attachments.add(attachment);
//		}
//		reportingDto.setAttachments(attachments);
		reportDataWebService.attachmentSubmitted(reportingDto, jobId,
				userInfoId, launchId, reportDescription);
		super.getRequestResult().setMessage("附件上报成功");
		super.getRequestResult().setRsltCode("0");
		ActionContext.getContext().getSession().put("_lastOpResult",
				super.getRequestResult());

	   return SUCCESS;  

	}

	public File[] getFiles() {
		return files;
	}

	public void setFiles(File[] files) {
		this.files = files;
	}

	public String[] getFilesFileName() {
		return filesFileName;
	}

	public void setFilesFileName(String[] filesFileName) {
		this.filesFileName = filesFileName;
	}

	public String[] getFilesNode() {
		return filesNode;
	}

	public void setFilesNode(String[] filesNode) {
		this.filesNode = filesNode;
	}

	public long getJobId() {
		return jobId;
	}

	public void setJobId(long jobId) {
		this.jobId = jobId;
	}

	public String getReportDescription() {
		return reportDescription;
	}

	public void setReportDescription(String reportDescription) {
		this.reportDescription = reportDescription;
	}

	public long getLaunchId() {
		return launchId;
	}

	public void setLaunchId(long launchId) {
		this.launchId = launchId;
	}

    public String getFromFlag() {
        return fromFlag;
    }

    public void setFromFlag(String fromFlag) {
        this.fromFlag = fromFlag;
    }
	
	
	

}